﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace cloud_music.chuangjiangedan_ng
{
    /// <summary>
    /// 通用方法类
    /// </summary>
    class sql
    {
        string lianjie = "Data Source=172.16.1.45;Initial Catalog=DB_A2011_G03;Persist Security Info=True;User ID=a2011;Password=Abcd_!23^";
        SqlConnection SqlConnection = null;
        //构造方法（当有人new这个类创建对象时自动执行的方法叫做构造方法）


        /// <summary>
        /// 验证登录通用方法
        /// </summary>
        /// <param name="tianjian"></param>
        public sql(string tianjian)
        {
            //保证数据库一点连接成功
            if (SqlConnection == null)
            {
                this.SqlConnection = new SqlConnection(lianjie);
            }
            string sql = string.Format("SELECT count(*) FROM [student management system].[dbo].[Admintble] where" + tianjian);
            int chekID = 0;
            //打开连接
            SqlConnection.Open();
            //调用方法查询
            SqlCommand SqlCommand = new SqlCommand(sql, SqlConnection);
            //  转换int类型
            chekID = (int)SqlCommand.ExecuteScalar();
            //关闭连接
            SqlConnection.Close();
        }
      







        /// <summary>
        /// 增加删除修改通用方法
        /// </summary>
        /// <param name="sqlyuju"></param>
        /// <returns></returns>

        public int addandDeleteandupdeat(string sqlyuju)
        {
            //保证数据库一点连接成功
            if (SqlConnection == null)
            {
                this.SqlConnection = new SqlConnection(lianjie);
            }

            SqlConnection.Open();//打开数据库连接
            SqlCommand sqlCommand = new SqlCommand(sqlyuju, SqlConnection);
            //执行sql语句返回影响行数
            int rows = sqlCommand.ExecuteNonQuery();
            //关闭数据库连接
            SqlConnection.Close();
            return rows;
        }

    }
}
